<!--
 * @Author: your name
 * @Date: 2021-04-26 18:45:16
 * @LastEditTime: 2021-05-20 14:07:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\test\printSupplement.vue
-->
<template>
    <div class="printSupplement-main-box">
        <el-dialog
        title="补码"
        :visible="visible"
        width="40%"
        @close="$emit('update:visible', false)"
        :close-on-click-modal='false'
        >
            <baseForm :option='option' v-model="form" ref='child'></baseForm>
            <span slot="footer" class="dialog-footer">
                <el-button @click="$emit('update:visible', false)">{{$t('cancel')}}</el-button>
                <el-button :loading='loading' type="primary" @click="save()">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseForm from '../../../components/common/baseForm'
export default {
    components: {
        baseForm
    },
    props: {
        visible:{
            type:Boolean,
            default:false
        },
        printTypeSub:{
            type:Array,
            default:()=>{return []}
        },
        partList:{
            type:Array,
            default:()=>{return []}
        }
    },
    data() {
        return {
            form:{
                sn:'',
                type:''
            },
            loading:false,
            flag:false
        };
    },
    computed: {
        option(){
            return {
                columnNum:'1',
                data:[{
                    type:'select',
                    lable:'打印类型',
                    name:'type',
                    data:this.printTypeSub,
                    value:this.form.type,
                    rules:[{ required: true, message: '不能为空'}]
                },{
                    type:'select',
                    lable:'料号',
                    name:'partNo',
                    data:this.partList,
                    show:this.flag,
                    selectValue:'partNo',
                    selectLable:'partNo',
                    rules:[{ required: true, message: '不能为空'}]
                },{
                    type:'input',
                    lable:'SN',
                    name:'sn',
                    big:true,
                    rules:[{ required: true, message: '不能为空'},{ min: 8, max: 14, message: '长度在 8 到 14 个字符', trigger: 'blur' }]
                }
               ],
               
            }
        }
    },
    watch: {
        form:{
            handler(nv,ov){
                if(nv&&nv.type){
                    if(nv.type == 1){
                        this.flag = true
                    }else{
                        this.flag = false
                    }
                }
            },
            deep:true
        }
    },
    created() {

    },
    mounted() {

    },
    methods: {
        async save(){
            if(!this.$refs.child.save()){
                return
            }
            // this.loading = true
            // let res = await this.API.prtTaskCheckSn({
            //     inverterSn:this.form.sn
            // })
            // this.loading = false
            // if(res.success){
                this.loading = true
                let res2 = await this.API.prtTaskSaveRecord({
                    inverterSn:this.form.sn
                })
                this.loading = false
                if(res2.success){
                    this.$emit('csPrint',this.form)
                    this.$emit('update:visible', false)
                }else{
                    this.comm.showMsg(false)
                }
            // }else{
            //     this.comm.showMsg(false,'该sn不存在于数据库内，请检查sn')
            // }
            
        }
    },
};
</script>

<style  lang="less" scoped>

</style>
